package chapter07

import scala.collection.mutable

/**
 * Created with IntelliJ IDEA.
 * ClassName: Test08_MutableSet
 * Package: chapter07
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 *          Date: 2023-07-06
 *          Time: 14:02
 */

//可变集合Set
object Test08_MutableSet {
  def main(args: Array[String]): Unit = {
    //创建可变集合
    val set:mutable.Set[Int] = mutable.Set(12,11,10,9)
    println(set) //Set(12, 9, 10, 11)

    //添加元素 添加元素 但是有返回值
    val set1 = set + 19
    println(set1)
    //直接加 本身变化
    set += 99
    println(set)
    //方法添加
    val ret = set1.add(111)
    println(ret) //返回值是一个boolean
    println(set1)

    //删除元素 删除元素11
    set1 -= 11
    println(set1)

    val ret1 = set1.remove(12)
    println(ret1)//和add一样 返回的是Boolean值
    println(set1)

    //合并集合
    val set3 = mutable.Set(12,1)
    val set6 = set1 ++ set3
    println(set6)

    //++=也可以操作
    set1 ++= set3
    println(set1)


  }
}
